package hzau.controller;

import hzau.pojo.Paper;
import hzau.pojo.requestParams.CourseRegisterParam;
import hzau.pojo.requestParams.PaperParam;
import hzau.result.Result;
import hzau.service.CourseService;
import hzau.service.PaperService;
import hzau.utils.JwtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("paper")
@Api(tags = "试卷相关接口")
public class PaperController {
    @Autowired
    PaperService paperService;
    @PostMapping("update")
    @ApiOperation("更新试卷信息")
    public Result update( @RequestBody Paper paper){
        return paperService.update(paper);
    }
    @PostMapping("register")
    @ApiOperation("新增试卷")
    public Result register( @RequestBody PaperParam paper,@RequestHeader("token") String token){
        return paperService.register(paper,token);
    }
    @DeleteMapping("delete")
    @ApiOperation("删除试卷")
    public Result delete(Long id){
        return paperService.delete(id);
    }
    @PostMapping("getAllQuestion")
    @ApiOperation("获取该试卷的试题")
    public Result getAllQuestion(Long id){
        return paperService.getAllQuestion(id);
    }
    @GetMapping("get/getByTeacherId/{page}")
    @ApiOperation("根据教师ID查询试卷列表")
    public Result getByTeacherId(@RequestHeader("token") String token,@PathVariable Integer page){
        Long  teacherId = JwtUtils.getUserId(token);
        return paperService.getByTeacherId(teacherId,page);
    }
    @GetMapping("get/{id}")
    @ApiOperation("根据ID查询试卷")
    public Result getById(@PathVariable Long id){
        return paperService.getById(id);
    }
    @PostMapping("update/state")
    @ApiOperation("更新试卷状态信息")
    public Result updateState( Long id,Short state){
        return paperService.updateState(id,state);
    }
    @GetMapping("get/getByReviewId/{reviewId}/{page}")
    @ApiOperation("查询需要评审的试卷")
    public Result getByReviewId( @RequestHeader("token") String token,@PathVariable Integer page){
        Long  reviewId = JwtUtils.getUserId(token);
        return paperService.getByReviewId(reviewId,page);
    }
    @PostMapping("/advice")
    @ApiOperation("更新专家建议")
    public Result updateAdvice(String advice,Long paperId){
        return paperService.updateAdvice(advice,paperId);
    }
    @PostMapping("/presidentAdvice")
    @ApiOperation("更新专家建议")
    public Result presidentAdvice(String advice,Long paperId){
        return paperService.presidentAdvice(advice,paperId);
    }
    @PostMapping("/deletePaper")
    @ApiOperation("删除试卷")
    public Result deletePaper(Long paperId){
        return paperService.deletePaper(paperId);
    }
    @GetMapping("/getPresidentReviewPaper/{page}")
    @ApiOperation("获取院长评审")
    public Result getPresidentReviewPaper(@RequestHeader("token") String token,@PathVariable Integer page){
        return paperService.getPresidentReviewPaper(token,page);
    }
    @PostMapping("/genPaper")
    @ApiOperation("生成试卷")
    public Result genPaper(Long paperId) throws Exception {
        return paperService.genPaper(paperId);
    }
    @PostMapping("/getRecentYearPaper")
    @ApiOperation("获取最近三年试卷")
    public Result getRecentYearPaper(Long paperId) throws Exception {
        return paperService.getRecentYearPaper(paperId);
    }
    @PostMapping("/getRecentYearPaperSimilarity")
    @ApiOperation("获取最近三年试卷相似度")
    public Result getRecentYearPaperSimilarity(Long paperId) throws Exception {
        return paperService.getRecentYearPaperSimilarity(paperId);
    }
}
